package com.iplant.aps.service.po.aps;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.iplant.aps.service.po.oms.OMSOrder;
import com.iplant.base.po.BasePO;
import com.iplant.base.po.enums.DBSchemas;
import com.iplant.base.utils.annotation.field.DBField;
import com.iplant.base.utils.annotation.condition.DBCondition;
import com.iplant.base.utils.annotation.join.DBJoin;
import com.iplant.base.utils.annotation.po.DBBasePO;
import com.iplant.pdm.service.basicenum.fpc.FPCRouteType;
import com.iplant.pdm.service.po.bop.FPCRoutePart;

import java.util.*;

@DBBasePO(TableName = "aps_task_part", Name = false, CheckName = {"Code"}, CodeAuto = true, CodePrefix = "APSP" +
        "-{yyyyMM}-", Schemas = DBSchemas.APS)
public class APSTaskPart extends BasePO {

    public APSTaskPart() {
        super();
    }

    public APSTaskPart(FPCRoutePart wFPCRoutePart, OMSOrder wOMSOrder) {
        super();
        LineID = wOMSOrder.LineID;
        OrderID = wOMSOrder.ID;
        ProductID = wOMSOrder.ProductID;
        RoutePartID = wFPCRoutePart.ID;
        WorkShopID = wFPCRoutePart.WorkShopID;
        WorkAreaID = wFPCRoutePart.WorkAreaID;
        StationID = wFPCRoutePart.StationID;
        PartType = wFPCRoutePart.PartType;
        RouteType = wFPCRoutePart.RouteType;
        PlantNum = wOMSOrder.FQTYPlan;
        Active = 1;
    }

    @DBCondition
    @DBField
    public int LineID = 0;

    @DBJoin(name = "Name", tableName = "fmc_line", tableAsName = "fmc_line1", Schemas = DBSchemas.PDM,
            MainTableField = "LineID")
    public String LineName = "";

    @DBCondition(CompareType = DBCondition.DBCompareType.in)
    @DBField
    public int OrderID = 0;

    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Code", tableName = "oms_order", tableAsName = "o1",
            Schemas = DBSchemas.APS,
            MainTableField = "OrderID")
    public String OrderNo = "";

    /**
     * 订单状态
     */
    @DBCondition
    @DBJoin(name = "Status", tableName = "oms_order", tableAsName = "o1", Schemas = DBSchemas.APS, MainTableField =
            "OrderID")
    public int OrderStatus = 0;

    @DBCondition
    @DBField
    public int ProductID = 0;

    @DBJoin(name = "Code", tableName = "fpc_product", tableAsName = "fpc_product1", Schemas = DBSchemas.PDM,
            MainTableField = "ProductID")
    public String ProductCode = "";


    @DBJoin(name = "ComponentNumber", tableName = "fpc_product", tableAsName = "fpc_product1", Schemas = DBSchemas.PDM,
            MainTableField = "ProductID")
    public int ComponentNumber = 1;

    @DBCondition
    @DBField
    public int RoutePartID = 0;

    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Name", tableName = "fpc_routepart", tableAsName = "fpc_routepart1", Schemas = DBSchemas.PDM,
            MainTableField = "RoutePartID")
    public String RoutePartName = "";

    /**
     * 工艺顺序（辅助属性）
     */
    @DBJoin(name = "OrderID", tableName = "fpc_routepart", tableAsName = "fpc_routepart1", Schemas = DBSchemas.PDM,
            MainTableField = "RoutePartID")
    public int RoutePartOrder = 0;

    @DBJoin(name = "ComponentType", tableName = "fpc_routepart", tableAsName = "fpc_routepart1", Schemas =
            DBSchemas.PDM,
            MainTableField = "RoutePartID")
    public int ComponentType = 0;

    /**
     * 车间ID
     */
    @DBCondition
    @DBField
    public int WorkShopID = 0;
    @DBJoin(name = "Name", tableName = "fmc_workshop", tableAsName = "workshop1", Schemas = DBSchemas.Basic,
            JoinIndex = 2,
            MainTableField = "WorkShopID")
    public String WorkShopName = "";
    /**
     * 车间编码
     */
    @DBJoin(name = "Code", tableName = "fmc_workshop", tableAsName = "workshop1", Schemas = DBSchemas.Basic,
            JoinIndex = 2,
            MainTableField = "WorkShopID")
    public String WorkShopCode = "";

    /**
     * 工区ID
     */
    @DBCondition
    @DBField
    public int WorkAreaID = 0;
    /**
     * 工区名称
     */
    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Name", tableName = "fmc_workarea", tableAsName = "workarea1", Schemas = DBSchemas.Basic,
            JoinIndex = 3,
            MainTableField = "WorkAreaID")
    public String WorkAreaName = "";
    /**
     * 工区编码
     */
    @DBJoin(name = "Code", tableName = "fmc_workarea", tableAsName = "workarea1", Schemas = DBSchemas.Basic,
            JoinIndex = 3,
            MainTableField = "WorkAreaID")
    public String WorkAreaCode = "";

    /**
     * 工位ID
     */
    @DBCondition
    @DBField
    public int StationID = 0;
    /**
     * 工位名称
     */
    @DBJoin(name = "Name", tableName = "fmc_station", tableAsName = "station1", Schemas = DBSchemas.Basic,
            JoinIndex = 4,
            MainTableField = "StationID")
    public String StationName = "";
    /**
     * 工位编码
     */
    @DBJoin(name = "Code", tableName = "fmc_station", tableAsName = "station1", Schemas = DBSchemas.Basic,
            JoinIndex = 4,
            MainTableField = "StationID")
    public String StationCode = "";

    private String PartEntityCode = "";
    private int PartEntityID = 0;
    private String PartEntityName = "";

    @DBField
    @DBCondition
    public int PartType = 0;//工艺集类型

    @DBField
    @DBCondition
    public int RouteType = 0;

    @DBCondition(CompareType = DBCondition.DBCompareType.ge, ParamName = "EndTime")
    @DBField
    public Calendar PartStartTime = Calendar.getInstance();

    @DBCondition(CompareType = DBCondition.DBCompareType.lt, ParamName = "StartTime")
    @DBField
    public Calendar PartEndTime = Calendar.getInstance();
    @DBField
    public float PlantNum = 0.0f;

    /**
     * 每天多少个
     */
    @DBField
    public Map<String, Float> PlanDayNum = new HashMap<>();

    /**
     * 每天  排程情况
     */
    @DBField
    public Map<String, List<APSCapacityUsed>> PlanDayDetailNum = new HashMap<>();

    public List<APSTaskPartPoint> TaskPartPointList = new ArrayList<>();

    /**
     * 排程类型  月 周
     */
    @DBCondition
    @DBField
    public int ShiftPeriod = 0;

    @DBCondition(CompareType = DBCondition.DBCompareType.in)
    @DBField
    public int Status = 0;

    /**
     * 实际执行数量
     */
    @DBField
    public float ActNum = 0.0f;

    /**
     * 是否为当前版本
     */
    @DBCondition
    @DBField
    public int IsCurrent = 0;

    @JsonProperty("OrderNo")
    public String getOrderNo() {
        return OrderNo;
    }

    public void setOrderNo(String orderNo) {
        OrderNo = orderNo;
    }

    @JsonProperty("ProductID")
    public int getProductID() {
        return ProductID;
    }

    public void setProductID(int productID) {
        ProductID = productID;
    }

    @JsonProperty("ProductCode")
    public String getProductCode() {
        return ProductCode;
    }

    public void setProductCode(String productCode) {
        ProductCode = productCode;
    }

    @JsonProperty("RoutePartName")
    public String getRoutePartName() {
        return RoutePartName;
    }

    public void setRoutePartName(String routePartName) {
        RoutePartName = routePartName;
    }

    @JsonProperty("RouteType")
    public int getRouteType() {
        return RouteType;
    }

    public void setRouteType(int routeType) {
        RouteType = routeType;
    }

    @JsonProperty("PlanDayDetailNum")
    public Map<String, List<APSCapacityUsed>> getPlanDayDetailNum() {
        return PlanDayDetailNum;
    }

    public void setPlanDayDetailNum(Map<String, List<APSCapacityUsed>> planDayDetailNum) {
        PlanDayDetailNum = planDayDetailNum;
    }

    @JsonProperty("RoutePartOrder")
    public int getRoutePartOrder() {
        return RoutePartOrder;
    }

    public void setRoutePartOrder(int routePartOrder) {
        RoutePartOrder = routePartOrder;
    }

    @JsonProperty("LineID")
    public int getLineID() {
        return LineID;
    }

    public void setLineID(int lineID) {
        LineID = lineID;
    }

    @JsonProperty("OrderID")
    public int getOrderID() {
        return OrderID;
    }

    public void setOrderID(int orderID) {
        OrderID = orderID;
    }

    @JsonProperty("RoutePartID")
    public int getRoutePartID() {
        return RoutePartID;
    }

    public void setRoutePartID(int routePartID) {
        RoutePartID = routePartID;
    }

    @JsonProperty("WorkShopID")
    public int getWorkShopID() {
        return WorkShopID;
    }

    public void setWorkShopID(int workShopID) {
        WorkShopID = workShopID;
    }

    @JsonProperty("WorkShopName")
    public String getWorkShopName() {
        return WorkShopName;
    }

    public void setWorkShopName(String workShopName) {
        WorkShopName = workShopName;
    }

    @JsonProperty("WorkShopCode")
    public String getWorkShopCode() {
        return WorkShopCode;
    }

    public void setWorkShopCode(String workShopCode) {
        WorkShopCode = workShopCode;
    }

    @JsonProperty("WorkAreaID")
    public int getWorkAreaID() {
        return WorkAreaID;
    }

    public void setWorkAreaID(int workAreaID) {
        WorkAreaID = workAreaID;
    }

    @JsonProperty("WorkAreaName")
    public String getWorkAreaName() {
        return WorkAreaName;
    }

    public void setWorkAreaName(String workAreaName) {
        WorkAreaName = workAreaName;
    }

    @JsonProperty("WorkAreaCode")
    public String getWorkAreaCode() {
        return WorkAreaCode;
    }

    public void setWorkAreaCode(String workAreaCode) {
        WorkAreaCode = workAreaCode;
    }

    @JsonProperty("StationID")
    public int getStationID() {
        return StationID;
    }

    public void setStationID(int stationID) {
        StationID = stationID;
    }

    @JsonProperty("StationName")
    public String getStationName() {
        return StationName;
    }

    public void setStationName(String stationName) {
        StationName = stationName;
    }

    @JsonProperty("StationCode")
    public String getStationCode() {
        return StationCode;
    }

    public void setStationCode(String stationCode) {
        StationCode = stationCode;
    }

    @JsonProperty("PartType")
    public int getPartType() {
        return PartType;
    }

    public void setPartType(int partType) {
        PartType = partType;
    }

    @JsonProperty("PartStartTime")
    public Calendar getPartStartTime() {
        return PartStartTime;
    }

    public void setPartStartTime(Calendar partStartTime) {
        PartStartTime = partStartTime;
    }

    @JsonProperty("PartEndTime")
    public Calendar getPartEndTime() {
        return PartEndTime;
    }

    public void setPartEndTime(Calendar partEndTime) {
        PartEndTime = partEndTime;
    }

    @JsonProperty("PlantNum")
    public float getPlantNum() {
        return PlantNum;
    }

    public void setPlantNum(float plantNum) {
        PlantNum = plantNum;
    }

    @JsonProperty("PlanDayNum")
    public Map<String, Float> getPlanDayNum() {
        return PlanDayNum;
    }

    public void setPlanDayNum(Map<String, Float> planDayNum) {
        PlanDayNum = planDayNum;
    }

    @JsonProperty("ShiftPeriod")
    public int getShiftPeriod() {
        return ShiftPeriod;
    }

    public void setShiftPeriod(int shiftPeriod) {
        ShiftPeriod = shiftPeriod;
    }

    @JsonProperty("Status")
    public int getStatus() {
        return Status;
    }

    public void setStatus(int status) {
        Status = status;
    }

    @JsonProperty("ActNum")
    public float getActNum() {
        return ActNum;
    }

    public void setActNum(float actNum) {
        ActNum = actNum;
    }

    @JsonProperty("PartEntityCode")
    public String getPartEntityCode() {

        switch (FPCRouteType.getEnumType(RouteType)) {

            case RoutePartWorkshop:
                PartEntityCode = WorkShopCode;
                break;
            case RoutePartWorkArea:
                PartEntityCode = WorkAreaCode;
                break;
            case RoutePartStation:
                PartEntityCode = StationCode;
                break;
            case RoutePartPoint:
            case Default:
                break;
        }
        return PartEntityCode;
    }

    public void setPartEntityCode(String partEntityCode) {
        PartEntityCode = partEntityCode;
    }

    @JsonProperty("PartEntityID")
    public int getPartEntityID() {
        switch (FPCRouteType.getEnumType(RouteType)) {

            case RoutePartWorkshop:
                PartEntityID = WorkShopID;
                break;
            case RoutePartWorkArea:
                PartEntityID = WorkAreaID;
                break;
            case RoutePartStation:
                PartEntityID = StationID;
                break;
            case RoutePartPoint:
            case Default:
                break;
        }
        return PartEntityID;
    }

    public void setPartEntityID(int partEntityID) {
        PartEntityID = partEntityID;
    }

    @JsonProperty("PartEntityName")
    public String getPartEntityName() {
        switch (FPCRouteType.getEnumType(RouteType)) {

            case RoutePartWorkshop:
                PartEntityName = WorkShopName;
                break;
            case RoutePartWorkArea:
                PartEntityName = WorkAreaName;
                break;
            case RoutePartStation:
                PartEntityName = StationName;
                break;
            case RoutePartPoint:
            case Default:
                break;
        }
        return PartEntityName;
    }

    public void setPartEntityName(String partEntityName) {
        PartEntityName = partEntityName;
    }

    @JsonProperty("TaskPartPointList")
    public List<APSTaskPartPoint> getTaskPartPointList() {
        return TaskPartPointList;
    }

    public void setTaskPartPointList(List<APSTaskPartPoint> taskPartPointList) {
        TaskPartPointList = taskPartPointList;
    }

    @JsonProperty("LineName")
    public String getLineName() {
        return LineName;
    }

    public void setLineName(String lineName) {
        LineName = lineName;
    }

    @JsonProperty("ComponentNumber")
    public int getComponentNumber() {
        return ComponentNumber;
    }

    public void setComponentNumber(int componentNumber) {
        ComponentNumber = componentNumber;
    }

    @JsonProperty("ComponentType")
    public int getComponentType() {
        return ComponentType;
    }

    public void setComponentType(int componentType) {
        ComponentType = componentType;
    }

    @JsonProperty("IsCurrent")
    public int getIsCurrent() {
        return IsCurrent;
    }

    public void setIsCurrent(int isCurrent) {
        IsCurrent = isCurrent;
    }

    @JsonProperty("OrderStatus")
    public int getOrderStatus() {
        return OrderStatus;
    }

    public void setOrderStatus(int orderStatus) {
        OrderStatus = orderStatus;
    }
}
